package com.uphone.kingmall.adapter;

import android.text.TextUtils;
import android.view.View;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.china.zhuoyue.R;
import com.uphone.kingmall.bean.UserBanksBean;

import java.util.List;

/**
 * <pre>
 *     author : 王雨
 *     e-mail :
 *     time   : 2018/07/31
 *     desc   :
 *     version: 1.0
 * </pre>
 */
public class BankListAdapter extends BaseQuickAdapter<UserBanksBean.BankcardsBean, BaseViewHolder> {

    private BankItemClickListener listener;

    public BankListAdapter(int layoutResId, @Nullable List data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(final BaseViewHolder helper, final UserBanksBean.BankcardsBean item) {
        helper.setText(R.id.tv_bank_name, item.getBankName() + "");
        if (!TextUtils.isEmpty(item.getBankcardNo()) && item.getBankcardNo().length() > 4) {
            helper.setText(R.id.tv_cardid, item.getBankcardNo().substring(item.getBankcardNo().length() - 4));
        } else {
            helper.setText(R.id.tv_cardid, "");
        }
        helper.getView(R.id.tv_submit).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.delBankCard(v, helper.getLayoutPosition(), item);
                }
            }
        });
    }

    public void setOnBankItemClickListener(BankItemClickListener listener) {
        this.listener = listener;
    }

    public interface BankItemClickListener {
        void delBankCard(View v, int psotion, UserBanksBean.BankcardsBean item);
    }

}
